﻿package mortal.game.resource
{
    import com.gengine.resource.*;
    import com.gengine.utils.*;
    import extend.language.*;
    import flash.geom.*;
    import flash.utils.*;
    import mortal.game.resource.info.*;

    public class GameDefConfig extends Object
    {
        private var _data:Dictionary;
        private var _xmlDic:Dictionary;
        private var _npcEffectDic:Dictionary;
        private var _attackBattles:Dictionary;
        private var _dicAttributeName:Dictionary;
        private var _dicAttributeName2:Dictionary;
        private var _dicFightAttributeName:Dictionary;
        private var _petSkillBookFreshStarArr:Array = null;
        private var _aryPetGrowthFootEffectInfo:Array;
        private var _openHerizionMonsterAry:Dictionary;
        private var _doNotTargetToPlayerList:Dictionary;
        private var _firstMapShieldMonsterList:Dictionary;
        private static var _instance:GameDefConfig;

        public function GameDefConfig()
        {
            this._data = new Dictionary();
            this._xmlDic = new Dictionary();
            if (_instance != null)
            {
                throw new Error(" GameDefConfig 单例 ");
            }
            _instance = this;
            this.init();
            return;
        }// end function

        private function write(param1:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_4:String = null;
            var _loc_5:DefInfo = null;
            var _loc_6:Object = null;
            var _loc_2:* = param1.items as Array;
            for each (_loc_3 in _loc_2)
            {
                
                _loc_4 = _loc_3.type.toString();
                if (_loc_3.item is Array)
                {
                    for each (_loc_6 in _loc_3.item as Array)
                    {
                        
                        _loc_5 = new DefInfo();
                        _loc_5.type = _loc_4;
                        _loc_5.text = _loc_6.text;
                        _loc_5.id = _loc_6.id;
                        _loc_5.text1 = _loc_6.text1;
                        _loc_5.text2 = _loc_6.text2;
                        _loc_5.text3 = _loc_6.text3;
                        _loc_5.text4 = _loc_6.text4;
                        _loc_5.value = _loc_6.value;
                        this.addItem(_loc_5);
                    }
                }
                else
                {
                    _loc_5 = new DefInfo();
                    _loc_5.type = _loc_4;
                    _loc_5.text = _loc_3.item.text;
                    _loc_5.id = _loc_3.item.id;
                    _loc_5.text1 = _loc_3.item.text1;
                    _loc_5.text2 = _loc_3.item.text2;
                    _loc_5.text3 = _loc_3.item.text3;
                    _loc_5.text4 = _loc_3.item.text4;
                    _loc_5.value = _loc_3.item.value;
                    this.addItem(_loc_5);
                }
                this._xmlDic[_loc_4] = _loc_3;
            }
            return;
        }// end function

        private function addItem(param1:DefInfo) : void
        {
            this._data[param1.type + "-" + param1.id] = param1;
            return;
        }// end function

        public function getItem(param1:String, param2:int) : DefInfo
        {
            return this._data[param1 + "-" + param2] as DefInfo;
        }// end function

        public function getRewardDef(param1:int) : DefInfo
        {
            return this.getItem("reward", param1);
        }// end function

        public function getEntityDef(param1:int) : DefInfo
        {
            return this.getItem("entity", param1);
        }// end function

        public function getEBind(param1:int) : DefInfo
        {
            return this.getItem("EBind", param1);
        }// end function

        public function getEPrefixx(param1:int) : DefInfo
        {
            return this.getItem("EPrefix", param1);
        }// end function

        public function getECategory(param1:int) : DefInfo
        {
            return this.getItem("ECategory", param1);
        }// end function

        public function getSex(param1:int) : DefInfo
        {
            return this.getItem("ESex", param1);
        }// end function

        public function getSkillUseType(param1:int) : DefInfo
        {
            return this.getItem("ESkillUseType", param1);
        }// end function

        public function init() : void
        {
            var _loc_1:* = ConfigManager.instance.getJSONByFileName("gamedef.xml");
            this.write(_loc_1.root);
            return;
        }// end function

        public function getDefaultModel(param1:int) : DefInfo
        {
            return this.getItem("ECampModel", param1);
        }// end function

        public function getEquipName(param1:int) : String
        {
            return this.getItem("EEquip", param1).text;
        }// end function

        public function getFashionEquipName(param1:int) : String
        {
            return this.getItem("EFashionEquip", param1).text;
        }// end function

        public function getECamp(param1:int) : DefInfo
        {
            return this.getItem("ECamp", param1);
        }// end function

        public function getFightModeName(param1:int) : String
        {
            return this.getItem("EEntityFightMode", param1).text;
        }// end function

        public function getFightModeDec(param1:int) : String
        {
            return this.getItem("EEntityFightMode", param1).text1;
        }// end function

        public function getCampHtml(param1:int) : String
        {
            return HTMLUtil.addColor(this.getECamp(param1).text, this.getECamp(param1).text1);
        }// end function

        public function getECarrerShot(param1:int) : String
        {
            return this.getItem("ECareerShot", param1).text;
        }// end function

        public function getCarrer(param1:int) : String
        {
            return this.getItem("ECareer", param1).text;
        }// end function

        public function getECarrerSmallPic(param1:int) : String
        {
            return this.getItem("ECareerSmallPic", param1).text;
        }// end function

        public function getECarrerPic(param1:int) : String
        {
            return this.getItem("ECareerPic", param1).text;
        }// end function

        public function getECareer(param1:int) : DefInfo
        {
            return this.getItem("ECareer", param1);
        }// end function

        public function getECareerNameAddColoer(param1:int) : String
        {
            var _loc_2:* = this.getItem("ECareer", param1).text;
            var _loc_3:* = this.getItem("ECareer", param1).text1;
            return HTMLUtil.addColor(_loc_2, _loc_3);
        }// end function

        public function getEPrictUnitName(param1:int) : String
        {
            var _loc_2:String = "";
            var _loc_3:* = this.getItem("EPrictUnitName", param1);
            if (_loc_3)
            {
                _loc_2 = _loc_3.text;
            }
            return _loc_2;
        }// end function

        public function getEprictUnitGetWay(param1:int) : String
        {
            var _loc_2:String = "";
            var _loc_3:* = this.getItem("EPrictUnitName", param1);
            if (_loc_3)
            {
                _loc_2 = _loc_3.text4;
            }
            return _loc_2;
        }// end function

        public function getEPrictUnitName2(param1:int) : String
        {
            var _loc_2:String = "";
            var _loc_3:* = this.getItem("EPrictUnitName", param1);
            if (_loc_3)
            {
                _loc_2 = _loc_3.text3;
            }
            return _loc_2;
        }// end function

        public function getEPrictUnitImg(param1:int) : String
        {
            return this.getItem("EPrictUnitName", param1).text1;
        }// end function

        public function getEPrictUnitBigIcon(param1:int) : String
        {
            return this.getItem("EPrictUnitName", param1).text2;
        }// end function

        public function getEPrictNameAddColoer(param1:int, param2:String = "#f2de47") : String
        {
            var _loc_3:* = this.getEPrictUnitName(param1);
            return HTMLUtil.addColor(_loc_3, param2);
        }// end function

        public function getVipLevelIconUrl(param1:int, param2:int = 1) : String
        {
            var _loc_3:String = null;
            var _loc_4:* = this.getItem("EVipIconUrl", param1);
            if (_loc_4)
            {
                _loc_3 = _loc_4["text" + param2] + ".png";
            }
            return _loc_3;
        }// end function

        public function getYYpurpleIconUrl(param1:int, param2:int = 1) : String
        {
            var _loc_3:String = null;
            var _loc_4:* = this.getItem("EYYpurpleIconUrl", param1);
            if (_loc_4)
            {
                _loc_3 = _loc_4["text" + param2] + ".png";
            }
            return _loc_3;
        }// end function

        public function getPlatformThunderVipIconUrl(param1:int, param2:int = 1) : String
        {
            var _loc_3:String = null;
            var _loc_4:* = this.getItem("XunLeiVip", param1);
            if (_loc_4)
            {
                _loc_3 = _loc_4["text" + param2] + ".png";
            }
            return _loc_3;
        }// end function

        public function getPlatformSWVipIconUrl(param1:int) : String
        {
            var _loc_2:String = null;
            var _loc_3:* = this.getItem("ShunWangVip", param1);
            if (_loc_3)
            {
                _loc_2 = _loc_3["text1"] + ".png";
            }
            return _loc_2;
        }// end function

        public function getQQYearIconUrl(param1:int, param2:int = 0) : String
        {
            var _loc_3:String = null;
            var _loc_4:* = this.getItem("QQYellow", param1);
            if (_loc_4)
            {
                _loc_3 = _loc_4["text" + String((param2 + 1))] + ".png";
            }
            return _loc_3;
        }// end function

        public function getLoadMapConfig(param1:int) : Array
        {
            var _loc_2:* = this.getItem("LoadMapConfig", param1);
            if (_loc_2 == null)
            {
                return null;
            }
            return _loc_2.text.split(",");
        }// end function

        public function getGuildBuildingName(param1:int) : String
        {
            return this.getItem("EGuildStructureType", param1).text;
        }// end function

        public function getNpcByEffect(param1:int, param2:int = -1) : Object
        {
            var _loc_3:DefInfo = null;
            if (param2 == -1)
            {
                _loc_3 = this.getItem("NPCEffect", param1);
            }
            else
            {
                _loc_3 = this.getNpcEffectInfo(param1, param2);
            }
            if (!_loc_3)
            {
                throw new Error("未知的功能NPC effect=" + param1);
            }
            return {npcId:_loc_3.text1, mapId:_loc_3.text};
        }// end function

        private function getNpcEffectInfo(param1:int, param2:int) : DefInfo
        {
            var _loc_3:DefInfo = null;
            var _loc_4:Array = null;
            var _loc_5:Object = null;
            if (!this._npcEffectDic)
            {
                this._npcEffectDic = new Dictionary();
                _loc_4 = this._xmlDic["NPCEffect"].item as Array;
                for each (_loc_5 in _loc_4)
                {
                    
                    _loc_3 = new DefInfo();
                    _loc_3.type = "NPCEffect";
                    _loc_3.text = _loc_5.text;
                    _loc_3.id = _loc_5.id;
                    _loc_3.text1 = _loc_5.text1;
                    _loc_3.text2 = _loc_5.text2;
                    _loc_3.value = _loc_5.value;
                    this._npcEffectDic[_loc_3.id + "_" + _loc_3.text] = _loc_3;
                }
            }
            return this._npcEffectDic[param1 + "_" + param2];
        }// end function

        public function getERewardName(param1:int) : String
        {
            return this.getItem("reward", param1).text.split("　").join("");
        }// end function

        public function getChineseNum(param1:int) : String
        {
            var _loc_2:String = "";
            var _loc_3:* = this.getItem("ChineseNum", param1);
            if (_loc_3)
            {
                _loc_2 = _loc_3.text;
            }
            return _loc_2;
        }// end function

        public function getFigureToLetter(param1:int, param2:Boolean = true) : String
        {
            var _loc_3:String = "";
            var _loc_4:* = this.getItem("FigureToLetter", param1);
            if (_loc_4)
            {
                _loc_3 = param2 ? (_loc_4.text) : (_loc_4.text1);
            }
            return _loc_3;
        }// end function

        private function get attackBatters() : Dictionary
        {
            var _loc_1:int = 0;
            var _loc_2:DefInfo = null;
            if (!this._attackBattles)
            {
                this._attackBattles = new Dictionary();
                _loc_1 = 1;
                do
                {
                    
                    _loc_2 = this.getItem("AttackBatter", _loc_1++);
                    if (_loc_2)
                    {
                        this._attackBattles[_loc_2.text] = _loc_2.text1;
                    }
                }while (_loc_2 != null)
            }
            return this._attackBattles;
        }// end function

        public function isAttackBatter(param1:String, param2:String) : Boolean
        {
            if (this.attackBatters[param1] == param2)
            {
                return true;
            }
            return false;
        }// end function

        public function getLeadActions() : Array
        {
            return this._xmlDic["PlayerLeadAction"].item as Array;
        }// end function

        public function getAttributeName(param1:String, param2:Boolean = false, param3:int = 0) : String
        {
            var _loc_4:String = null;
            var _loc_5:Object = null;
            var _loc_6:String = null;
            if (!this._dicAttributeName)
            {
                this._dicAttributeName = new Dictionary();
                _loc_4 = param3 == 0 ? ("AttributeName") : ("AttributeName2");
                for each (_loc_5 in this._xmlDic[_loc_4].item)
                {
                    
                    this._dicAttributeName[_loc_5.text] = _loc_5.text1;
                }
            }
            if (param2)
            {
                for (_loc_6 in this._dicAttributeName)
                {
                    
                    if (_loc_6.toLowerCase() == param1.toLowerCase())
                    {
                        return this._dicAttributeName[_loc_6];
                    }
                }
            }
            else
            {
                return this._dicAttributeName[param1];
            }
            return null;
        }// end function

        public function getAttributeName2(param1:String, param2:Boolean = false) : String
        {
            var _loc_3:Object = null;
            var _loc_4:String = null;
            if (!this._dicAttributeName2)
            {
                this._dicAttributeName2 = new Dictionary();
                for each (_loc_3 in this._xmlDic["AttributeName2"].item)
                {
                    
                    this._dicAttributeName2[_loc_3.text] = _loc_3.text1;
                }
            }
            if (param2)
            {
                for (_loc_4 in this._dicAttributeName2)
                {
                    
                    if (_loc_4.toLowerCase() == param1.toLowerCase())
                    {
                        return this._dicAttributeName2[_loc_4];
                    }
                }
            }
            else
            {
                return this._dicAttributeName2[param1];
            }
            return null;
        }// end function

        public function getFightAttributeName(param1:String) : String
        {
            var _loc_2:Object = null;
            if (!this._dicFightAttributeName)
            {
                this._dicFightAttributeName = new Dictionary();
                for each (_loc_2 in this._xmlDic["FightRoleAttribute"].item)
                {
                    
                    this._dicFightAttributeName[_loc_2.text] = _loc_2.text1;
                }
            }
            return this._dicFightAttributeName[param1];
        }// end function

        public function getBloodName(param1:int) : String
        {
            var _loc_2:String = "";
            var _loc_3:* = this.getItem("PetBlood", param1);
            if (_loc_3)
            {
                _loc_2 = _loc_3.text;
            }
            return _loc_2;
        }// end function

        public function getBloodPostion(param1:int, param2:Boolean = false) : Array
        {
            var _loc_8:Point = null;
            var _loc_3:String = "";
            var _loc_4:* = this.getItem("PetBloodPosition", param1);
            if (param2)
            {
                _loc_3 = _loc_4.text;
            }
            else
            {
                _loc_3 = _loc_4.text1;
            }
            _loc_3 = _loc_3.replace(new RegExp(/[\[\]]""[\[\]]/g), "");
            var _loc_5:* = _loc_3.split(",");
            var _loc_6:* = new Array();
            var _loc_7:int = 0;
            while (_loc_7 < _loc_5.length)
            {
                
                _loc_8 = new Point();
                _loc_8.x = _loc_5[_loc_7];
                _loc_8.y = _loc_5[(_loc_7 + 1)];
                _loc_6.push(_loc_8);
                _loc_7 = _loc_7 + 2;
            }
            return _loc_6;
        }// end function

        public function getPetSkillBookFreshStarNum(param1:int) : Number
        {
            var _loc_3:String = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:Number = NaN;
            if (this._petSkillBookFreshStarArr == null)
            {
                _loc_3 = this.getItem("PetFreshSkillStarNum", 1).text;
                _loc_3 = _loc_3.replace(new RegExp(/[\[\]]""[\[\]]/g), "");
                this._petSkillBookFreshStarArr = _loc_3.split(",");
            }
            var _loc_2:int = 0;
            while (_loc_2 < this._petSkillBookFreshStarArr.length / 3)
            {
                
                _loc_4 = _loc_2 * 3;
                _loc_5 = this._petSkillBookFreshStarArr[_loc_4 + 0];
                _loc_6 = this._petSkillBookFreshStarArr[(_loc_4 + 1)];
                _loc_7 = this._petSkillBookFreshStarArr[_loc_4 + 2];
                if (_loc_6 == -1)
                {
                    return _loc_7;
                }
                if (param1 > _loc_6)
                {
                }
                else
                {
                    return _loc_7;
                }
                _loc_2++;
            }
            return 0;
        }// end function

        public function getGuildPositonInfo(param1:int) : DefInfo
        {
            return this.getItem("EGuildPostion", param1);
        }// end function

        public function getGuildPositonName(param1:int) : String
        {
            return this.getItem("EGuildPostion", param1).text;
        }// end function

        public function getGuildBossColorName(param1:int) : String
        {
            return this.getItem("EGuildBossColor", param1).text;
        }// end function

        public function getGuildPositonHtmlName(param1:int, param2:Boolean = true, param3:Boolean = true) : String
        {
            var _loc_4:* = this.getGuildPositonInfo(param1);
            if (param2)
            {
                if (param3)
                {
                    return HTMLUtil.addColor(_loc_4.text2, _loc_4.text1);
                }
                return _loc_4.text2;
            }
            else
            {
                if (param3)
                {
                    return HTMLUtil.addColor(_loc_4.text, _loc_4.text1);
                }
            }
            return _loc_4.text;
        }// end function

        public function getBattlefieldForceInfo(param1:int) : DefInfo
        {
            return this.getItem("EBattlefieldForce", param1);
        }// end function

        public function getBattlefieldResetForceInfo(param1:int) : DefInfo
        {
            return this.getItem("EBattlefieldResetForce", param1);
        }// end function

        public function getBattlefieldForceHtml(param1:int) : String
        {
            var _loc_2:* = this.getBattlefieldForceInfo(param1);
            if (_loc_2)
            {
                return HTMLUtil.addColor(_loc_2.text, _loc_2.text1);
            }
            return "";
        }// end function

        public function getGuildWarPlaceName(param1:int) : String
        {
            var _loc_2:* = this.getItem("EGuildWarPlace", param1);
            if (_loc_2)
            {
                return _loc_2.text;
            }
            return Language.getStringByParam(20600, param1);
        }// end function

        public function getHurtTypeName(param1:int) : String
        {
            var _loc_2:* = this.getItem("EHurtType", param1);
            if (_loc_2)
            {
                return _loc_2.text;
            }
            return Language.getString(20601);
        }// end function

        public function getQuitCopyTip(param1:int) : DefInfo
        {
            return this.getItem("QuitCopyTip", param1);
        }// end function

        public function getNpcMaxScale(param1:int) : DefInfo
        {
            return this.getItem("NpcMaxScale", param1);
        }// end function

        public function getPetGrowthFootEffect(param1:int) : String
        {
            var _loc_2:DefInfo = null;
            var _loc_3:int = 0;
            if (!this._aryPetGrowthFootEffectInfo)
            {
                this._aryPetGrowthFootEffectInfo = new Array();
                _loc_3 = 1;
                while (_loc_3 <= 4)
                {
                    
                    _loc_2 = this.getItem("EPetGrouthEffect", _loc_3);
                    this._aryPetGrowthFootEffectInfo.push(_loc_2);
                    _loc_3++;
                }
            }
            _loc_3 = this._aryPetGrowthFootEffectInfo.length - 1;
            while (_loc_3 >= 0)
            {
                
                _loc_2 = this._aryPetGrowthFootEffectInfo[_loc_3];
                if (param1 >= int(_loc_2.value))
                {
                    return _loc_2.text;
                }
                _loc_3 = _loc_3 - 1;
            }
            return "";
        }// end function

        public function getEquipGemHoleNum(param1:int) : int
        {
            var _loc_2:* = int(param1 / 10) * 10;
            var _loc_3:* = this.getItem("EEquipGemHoleNum", _loc_2);
            if (_loc_3)
            {
                return int(_loc_3.value);
            }
            return 0;
        }// end function

        public function getForgingPanelOpenLevel(param1:int) : int
        {
            var _loc_2:* = this.getItem("EForgingPanelOpenLevel", param1);
            if (_loc_2 != null)
            {
                return int(_loc_2.value);
            }
            return 0;
        }// end function

        public function getSystemOpenLevel(param1:int) : int
        {
            var _loc_2:* = this.getItem("SystemFunctionOpenLevel", param1);
            if (_loc_2)
            {
                return int(_loc_2.value);
            }
            return -1;
        }// end function

        public function getSystemCloseLevel(param1:int) : int
        {
            var _loc_2:* = this.getItem("SystemFunctionOpenLevel", param1);
            if (_loc_2)
            {
                return int(_loc_2.text1);
            }
            return -1;
        }// end function

        public function getDailyViewConfigId(param1:int) : int
        {
            var _loc_2:* = this.getItem("DailyViewConfigId", param1);
            if (_loc_2)
            {
                return int(_loc_2.value);
            }
            return -1;
        }// end function

        public function isOpenHerizionKilMonster(param1:int) : Boolean
        {
            var _loc_2:DefInfo = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            if (!this._openHerizionMonsterAry)
            {
                this._openHerizionMonsterAry = new Dictionary();
                _loc_2 = this.getItem("OpenHerizionKilMonster", 1);
                _loc_3 = _loc_2.text.split(",");
                _loc_4 = 0;
                while (_loc_4 < _loc_3.length)
                {
                    
                    this._openHerizionMonsterAry[int(_loc_3[_loc_4])] = 1;
                    _loc_4++;
                }
            }
            return this._openHerizionMonsterAry[param1];
        }// end function

        public function isDoNotTargetToPlayer(param1:int) : Boolean
        {
            var _loc_2:DefInfo = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            if (!this._doNotTargetToPlayerList)
            {
                this._doNotTargetToPlayerList = new Dictionary();
                _loc_2 = this.getItem("DoNotTargetToPlayerList", 1);
                _loc_3 = _loc_2.text.split(",");
                _loc_4 = 0;
                while (_loc_4 < _loc_3.length)
                {
                    
                    this._doNotTargetToPlayerList[int(_loc_3[_loc_4])] = 1;
                    _loc_4++;
                }
            }
            return this._doNotTargetToPlayerList[param1];
        }// end function

        public function isFirstMapShieldMonster(param1:int) : Boolean
        {
            var _loc_2:DefInfo = null;
            var _loc_3:Array = null;
            var _loc_4:int = 0;
            if (!this._firstMapShieldMonsterList)
            {
                this._firstMapShieldMonsterList = new Dictionary();
                _loc_2 = this.getItem("FirstMapShieldMonsterList", 1);
                _loc_3 = _loc_2.text.split(",");
                _loc_4 = 0;
                while (_loc_4 < _loc_3.length)
                {
                    
                    this._firstMapShieldMonsterList[int(_loc_3[_loc_4])] = 1;
                    _loc_4++;
                }
            }
            return this._firstMapShieldMonsterList[param1];
        }// end function

        public function get xmlDic() : Dictionary
        {
            return this._xmlDic;
        }// end function

        public function getOtherSkillTypeByPosType(param1:int) : int
        {
            var _loc_2:Object = null;
            for each (_loc_2 in this._xmlDic["OtherSkillInfo"].item)
            {
                
                if (param1 >= int(_loc_2.text) && param1 < int(_loc_2.text1))
                {
                    return int(_loc_2.text2);
                }
            }
            return 0;
        }// end function

        public function getOtherSkillPostTypeRect(param1:int) : Array
        {
            var _loc_3:Object = null;
            var _loc_2:Array = [];
            for each (_loc_3 in this._xmlDic["OtherSkillInfo"].item)
            {
                
                if (param1 == int(_loc_3.text2))
                {
                    _loc_2.push(int(_loc_3.text));
                    _loc_2.push(int(_loc_3.text1));
                    return _loc_2;
                }
            }
            return _loc_2;
        }// end function

        public function getExchangeShopEnterLevel(param1:int) : int
        {
            return int(this.getItem("EExchangeShop", param1).text);
        }// end function

        public static function get instance() : GameDefConfig
        {
            if (_instance == null)
            {
                _instance = new GameDefConfig;
            }
            return _instance;
        }// end function

    }
}
